// WJSHWebApi.Startup
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
using WJSHWebApi.InterFace;
using WJSHWebApi.Server;

public class Startup
{
	public IConfiguration Configuration
	{
		get;
	}

	public Startup(IConfiguration configuration)
	{
		Configuration = configuration;
	}

	public void ConfigureServices(IServiceCollection services)
	{
		services.AddControllers();
		services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest).AddJsonOptions(delegate(JsonOptions option)
		{
			option.JsonSerializerOptions.PropertyNamingPolicy = null;
		});
		IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
		string alloweHosts = config["AllowedHosts"];
		services.AddCors(delegate(CorsOptions options)
		{
			options.AddPolicy("cors", delegate(CorsPolicyBuilder builder)
			{
				builder.WithOrigins(alloweHosts).AllowAnyOrigin().AllowAnyMethod()
					.AllowAnyHeader();
			});
		});
		services.AddSwaggerGen(delegate(SwaggerGenOptions c)
		{
			c.SwaggerDoc("v1", new OpenApiInfo
			{
				Version = "Ver:1.0.0",
				Title = "测试管理系统",
				Description = "测试管理系统：包括人员信息、团队管理等。",
				Contact = new OpenApiContact
				{
					Name = "Mr.Gao",
					Email = "979171607@qq.com"
				}
			});
		});
		services.AddSingleton<IDBInterface, DapperServer>();
		services.AddHostedService<KingDeeServer>();
		services.AddSingleton<KingDeeCKUDServer>();
		services.AddSingleton<PDserver>();
		services.AddSingleton<RKDServer>();
	}

	public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
	{
		if (env.IsDevelopment())
		{
			app.UseDeveloperExceptionPage();
		}
		app.UseSwagger();
		app.UseSwaggerUI(delegate(SwaggerUIOptions c)
		{
			c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
		});
		app.UseRouting();
		app.UseCors("cors");
		app.UseAuthorization();
		app.UseEndpoints(delegate(IEndpointRouteBuilder endpoints)
		{
			endpoints.MapControllers();
		});
	}
}
